% clears unneceesary vriables after
% invoking readrts reads the header
% compute cal. table according to gain settings etc;

readrts;
Notchi = NotchF(2:5);		% NOTE ! there may be problems 
IsNotch = Filt(2:5);		%        if notch do not have right dimension..
hpb1 = Filt(1);			% NOTE ! high pass filter is always disabled
prob = [Exd Eyd Eyd Eyd Eyd];	% 	 in calib05.m
gain = [Exa Eya Hxa Hya Hza];
clear Bden Record3 Bdend Bddm Count Record4 hpf Bdst Record5;
clear Bdstart MaxRecord ans nt Filt NBlocks array nlines Events ;
clear NotchF dummy Record1 factor matrix;
selblock =  [128;256;512;1024;2048;4096];
str = {'128','256','512','1024','2048','4096'};
[s,v] = listdlg('PromptString','Select nfft:',...
                     'SelectionMode','single',...
                      'ListSize',[100 50],'ListString',str);
block = selblock(s);
notch = Notchi(find(IsNotch>0)); 
PAI = 3.1415926535897;

for i = 1:nchannel,
[cplx,frq1] = calib05(i,nband,block,prob(i),notch,hpb1,gain(i));
CalData(i,:) = cplx;
end;

% delete it-- 11.7.2002
%load k:\manoj\data\mnaa200411.tr1;
load \\dell01\e\manoj\data\sys-trfn\ku301033.tr3;
Cdata = ku301033;
absEp = Cdata(:,2:4);
absEp(:,2) = [];
angleEp = Cdata(:,3:5);
angleEp(:,2) = [];

absHp = Cdata(:,6:10);
absHp(:,2) = [];
absHp(:,3) = [];

angleHp = Cdata(:,7:11);
angleHp(:,2) = [];
angleHp(:,3) = [];


absE    =  abs(CalData(1:2,:));
angleE  =  angle(CalData(1:2,:))*(180/PAI);

absH    =  abs(CalData(3:5,:));
angleH  =  angle(CalData(3:5,:))*(180/PAI);

subplot(2,1,1);
loglog(frq1,absE,frq1,1./absEp);

xlabel('frequency (Hz)');
ylabel('amplitude (V/E)');
subplot(2,1,2);
loglog(frq1,absH,frq1,1./absHp);
legend('Computed','ProcMT');
xlabel('frequency (Hz)');
ylabel('amplitude');
title('Amplitude E & H');
pause;

subplot(2,1,1);
semilogx(frq1,angleE,frq1,0-angleEp);
xlabel('frequency (Hz)');
ylabel('phase (degrees)');
subplot(2,1,2);
semilogx(frq1,angleH,frq1,0-angleHp);
legend('Computed','ProcMT');
xlabel('frequency (Hz)');
ylabel('phase (degrees)');
title('Phases E & H');